//
//  ViewController.m
//  21网络数据请求
//
//  Created by dllo on 16/8/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *networkImage;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)syncConect:(id)sender {
    
    


//    NSLog(@"点击");
//    NSURLSession *urlSession = [NSURLSession sharedSession];
//    NSURL *imageURL = [NSURL URLWithString:@"http://img4.duitang.com/uploads/item/201207/28/20120728105310_jvAjW.thumb.600_0.jpeg"];
//    NSMutableURLRequest *imageURLRequest = [NSMutableURLRequest requestWithURL:imageURL];
//    imageURLRequest.HTTPMethod = @"GET";
//    NSURLResponse *response = nil;
//    NSError *error = nil;
//    NSData *data = [NSURLConnection sendSynchronousRequest:imageURLRequest returningResponse:&response error:&error];
//    if (data) {
//        _networkImage.image = [UIImage imageWithData:data];
//    }
    NSURL *imageURL = [NSURL URLWithString:@"http://www.lingyu.me/wp-content/uploads/2016/08/www.lingyu.me_20160808081654350.jpg"];
//    NSLog(@"%@",imageURL);
    NSMutableURLRequest *imageURLRequest = [NSMutableURLRequest requestWithURL:imageURL];
    NSLog(@"%@",imageURLRequest);
    imageURLRequest.HTTPMethod = @"GET";
    NSURLResponse *response = nil;
    NSError *error = nil;
    //    同步请求
    //    参数1.请求request
    //    参数2. response指针的地址
    //    参数3.error指针的地址
    NSData *data = [NSURLConnection sendSynchronousRequest:imageURLRequest returningResponse:&response error:&error];
//    NSLog(@"%@",data);
    
    if (data) {
        _networkImage.image = [UIImage imageWithData:data];
    }

    
}
- (IBAction)qingQiu:(id)sender {
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
